import {Avatar, Box, FlatList, HStack, Pressable, Spacer, Text, VStack} from 'native-base';
import React from 'react';
import {SafeAreaView, useSafeAreaInsets} from 'react-native-safe-area-context';
import {Search} from '@/components';
import {useNavigation} from '@react-navigation/native';

const Operation = () => {
  const navigation = useNavigation();

  const data = [
    {
      id: 1,
      fullName: '小Ling',
      nickname: '三哥',
      timeStamp: '12:47 PM',
      recentText: 'Good Day!',
      avatarUrl: 'https://randomuser.me/api/portraits/men/1.jpg',
    },
    {
      id: 2,
      fullName: '回热加热器超温会诊室',
      nickname: '会诊室',
      timeStamp: '12:47 PM',
      recentText: 'Good Day!',
      avatarUrl: 'https://randomuser.me/api/portraits/men/2.jpg',
    },
    {
      id: 3,
      fullName: '张三',
      nickname: '三哥',
      timeStamp: '12:47 PM',
      recentText: 'Good Day!',
      avatarUrl: 'https://randomuser.me/api/portraits/men/3.jpg',
    },
    {
      id: 4,
      fullName: '李四',
      nickname: '四哥',
      timeStamp: '12:47 PM',
      recentText: 'Good Day!',
      avatarUrl: 'https://randomuser.me/api/portraits/men/4.jpg',
    },
    {
      id: 5,
      fullName: '王五',
      nickname: '五哥',
      timeStamp: '12:47 PM',
      recentText: 'Good Day!',
      avatarUrl: 'https://randomuser.me/api/portraits/men/5.jpg',
    },
    {
      id: 6,
      fullName: '赵六',
      nickname: '六哥',
      timeStamp: '12:47 PM',
      recentText: 'Good Day!',
      avatarUrl: 'https://randomuser.me/api/portraits/men/6.jpg',
    },
    {
      id: 7,
      fullName: '钱七',
      nickname: '七哥',
      timeStamp: '12:47 PM',
      recentText: 'Good Day!',
      avatarUrl: 'https://randomuser.me/api/portraits/men/7.jpg',
    },
    {
      id: 8,
      fullName: '孙八',
      nickname: '八哥',
      timeStamp: '12:47 PM',
      recentText: 'Good Day!',
      avatarUrl: 'https://randomuser.me/api/portraits/men/8.jpg',
    },
    {
      id: 9,
      fullName: '周九',
      nickname: '九哥',
      timeStamp: '12:47 PM',
      recentText: 'Good Day!',
      avatarUrl: 'https://randomuser.me/api/portraits/men/9.jpg',
    },
    {
      id: 10,
      fullName: '吴十',
      nickname: '十哥',
      timeStamp: '12:47 PM',
      recentText: 'Good Day!',
      avatarUrl: 'https://randomuser.me/api/portraits/men/10.jpg',
    },
    {
      id: 11,
      fullName: '郑十一',
      nickname: '十一哥',
      timeStamp: '12:47 PM',
      recentText: 'Good Day!',
      avatarUrl: 'https://randomuser.me/api/portraits/men/11.jpg',
    },
    {
      id: 12,
      fullName: '王十二',
      nickname: '十二哥',
      timeStamp: '12:47 PM',
      recentText: 'Good Day!',
      avatarUrl: 'https://randomuser.me/api/portraits/men/12.jpg',
    },
    {
      id: 13,
      fullName: '李十三',
      nickname: '十三哥',
      timeStamp: '12:47 PM',
      recentText: 'Good Day!',
      avatarUrl: 'https://randomuser.me/api/portraits/men/13.jpg',
    },
    {
      id: 14,
      fullName: '张十四',
      nickname: '十四哥',
      timeStamp: '12:47 PM',
      recentText: 'Good Day!',
      avatarUrl: 'https://randomuser.me/api/portraits/men/14.jpg',
    },
    {
      id: 15,
      fullName: '赵十五',
      nickname: '十五哥',
      timeStamp: '12:47 PM',
      recentText: 'Good Day!',
      avatarUrl: 'https://randomuser.me/api/portraits/men/15.jpg',
    },
    {
      id: 16,
      fullName: '钱十六',
      nickname: '十六哥',
      timeStamp: '12:47 PM',
      recentText: 'Good Day!',
      avatarUrl: 'https://randomuser.me/api/portraits/men/16.jpg',
    },
    {
      id: 17,
      fullName: '孙十七',
      nickname: '十七哥',
      timeStamp: '12:47 PM',
      recentText: 'Good Day!',
      avatarUrl: 'https://randomuser.me/api/portraits/men/17.jpg',
    },
    {
      id: 18,
      fullName: '周十八',
      nickname: '十八哥',
      timeStamp: '12:47 PM',
      recentText: 'Good Day!',
      avatarUrl: 'https://randomuser.me/api/portraits/men/18.jpg',
    },
    {
      id: 19,
      fullName: '吴十九',
      nickname: '十九哥',
      timeStamp: '12:47 PM',
      recentText: 'Good Day!',
      avatarUrl: 'https://randomuser.me/api/portraits/men/19.jpg',
    },
  ];
  const insets = useSafeAreaInsets();
  const onHnadleClickChat = item => {
    if (item.fullName === '小Ling') {
      navigation.navigate('Ling' as never);
    } else if (item.fullName === '回热加热器超温会诊室') {
      navigation.navigate('Chat' as never);
    }
  };
  return (
    <SafeAreaView style={{flex: 1, backgroundColor: 'white', paddingTop: insets.top}} edges={['left', 'right']}>
      <Search />
      <FlatList
        data={data}
        px="3"
        renderItem={({item}) => (
          <Pressable onPress={() => onHnadleClickChat(item)}>
            <Box pl={['0', '4']} pr={['0', '5']} py="2">
              <HStack space={[2, 3]} justifyContent="space-between">
                <Avatar
                  size="16"
                  source={{
                    uri: item.avatarUrl,
                  }}>
                  <Avatar.Badge position="absolute" top="0" right="0" size="6" bg="red.500" alignItems="center" justifyItems="center" justifyContent="center">
                    <Text color="white">{Math.floor(Math.random() * 10) + 1}</Text>
                  </Avatar.Badge>
                </Avatar>
                <VStack size="16" justifyContent="space-around">
                  <Text color="coolGray.800" fontSize="md" bold>
                    {item.fullName}
                  </Text>
                  <Text color="coolGray.600">{item.recentText}</Text>
                </VStack>
                <Spacer />
                <Text fontSize="xs" color="coolGray.800" alignSelf="flex-start">
                  {item.timeStamp}
                </Text>
              </HStack>
            </Box>
          </Pressable>
        )}
        keyExtractor={item => item.id.toString()}
      />
    </SafeAreaView>
  );
};
export default Operation;
